package com.amphiprion.prototype.component.animation;

import android.view.animation.Interpolator;

public class TranslationComponentAnimation extends GameComponentAnimation {
	private float deltaX;
	private float deltaY;
	private float startX;
	private float endX;
	private float startY;
	private float endY;

	private Interpolator itp;

	public TranslationComponentAnimation(long duration, long delay, float deltaX, float deltaY) {
		this.delay = delay;
		this.deltaX = deltaX;
		this.deltaY = deltaY;
		this.duration = duration;
	}

	@Override
	protected float getInterpolatedProgress(float progress) {
		if (itp != null) {
			return itp.getInterpolation(progress);
		} else {
			return super.getInterpolatedProgress(progress);
		}
	}

	@Override
	protected void onUpdate(float progress) {
		cmp.setX((endX - startX) * progress + startX);
		cmp.setY((endY - startY) * progress + startY);
	}

	@Override
	public void start() {
		startX = cmp.getX();
		endX = startX + deltaX;
		startY = cmp.getY();
		endY = startY + deltaY;
	}

	public void setInterpolation(Interpolator itp) {
		this.itp = itp;
	}
}
